<?php
/**
 * Created by PhpStorm.
 * User: xiangfeng
 * Date: 2022/4/9
 * Time: 2:00 AM
 */

namespace app\api\http\middleware;


use app\api\extend\tools\SimpleModelConnectRedis;

class BaseMiddleware
{
    protected $redis;

    public function __construct()
    {
        $this->initialize();
    }

    protected function initialize()
    {
        $this->redis = SimpleModelConnectRedis::getInstance();
    }
//
//    /**
//     * @param $request
//     * @throws ApiExceptions
//     * @throws \think\db\exception\DataNotFoundException
//     * @throws \think\db\exception\DbException
//     * @throws \think\db\exception\ModelNotFoundException
//     */
//    protected function init($request)
//    {
//        $header = $request->header();
//        $flag = Data::isHttpJson(isset($header['content-type']) ? $header['content-type'] : '');
//        /************ Get 请求或者上传文件接口不需要设置content-type:application/json ***********/
//        if ($request->isGet() || 'v1/uploadFileToOss' == $request->pathinfo()) {
//            $flag = true;
//        }
//        if (!$flag) {
//            throw new ApiExceptions(ApiErr::VERIFY_CONTENT_TYPE);
//        }
//        /************  校验请求header参数是否合法 ************************/
//        try {
//            validate(AppsAuthValidate::class)->scene('apiauth')->check($header);
//        } catch (\Exception $exception) {
//            $apiErrConst = ApiErr::ERROR_PARAMS;
//            throw new ApiExceptions([$apiErrConst[0], $exception->getMessage()]);
//        }
//        $access_token = $header['access-token'];
//        $app_id = $header['appid'];
//        $timestamp = $header['timestamp'];
//        $param = $request->param();//请求参数
//        /*****客户端请求时间与服务端当前时间不能超过10分钟，否则拒绝访问******/
//        $timediff = Data::timediff($timestamp, time());
//        $min = isset($timediff['min']) ? (int)$timediff['min'] : 0;//分
//        $day = isset($timediff['day']) ? (int)$timediff['day'] : 0;//天
//        if ($day > 1 || $timestamp <= 0) {
//            throw new ApiExceptions(ApiErr::APPS_TIMESTAMP_ILLEGAL);
//        }
//        /**********根据客户端请求参数生成签名*********/
//        $apps_info = AppsModel::getAppsInfo($app_id);
//        $sign = Data::getSign($param, $apps_info['app_secret'], $timestamp);
//        if ($access_token != $sign) {
//            $apiErrConst = ApiErr::APPS_SIGN__ERROR;
//            throw new ApiExceptions([$apiErrConst[0], $sign]);
//        }
//    }
}